package maxScore;

public class Solution {
    public int maxScore(String s) {
        int rightOne = 0;
        for (int i = 1; i < s.length(); i++) {
            if(s.charAt(i) == '1')rightOne++;
        }
        // 最开始右边1的数量为s中除去第一个字符全部1的数量
        // 左边0的数量为s[0]
        int leftZero = s.charAt(0) == '0'?1:0;
        int ans = leftZero+rightOne;
        //  System.out.println(leftZero+" "+rightOne);
        for (int i = 1; i < s.length()-1; i++) {
            if(s.charAt(i) == '0'){
                leftZero++;
            }else {
                rightOne--;
            }
            //    System.out.println(leftZero+" "+rightOne+" "+i);
            ans = Math.max(ans,leftZero+rightOne);
        }
        return ans;
    }
}
